package com.ticket.web.controller.yanchu;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ticket.common.core.domain.model.LoginUser;
import com.ticket.common.utils.SecurityUtils;
import com.ticket.framework.web.service.TokenService;
import com.ticket.system.domain.YanchuUserInfo;
import com.ticket.system.domain.vo.UserInfoVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ticket.common.annotation.Log;
import com.ticket.common.core.controller.BaseController;
import com.ticket.common.core.domain.AjaxResult;
import com.ticket.common.enums.BusinessType;
import com.ticket.system.domain.YanchuMoviegoer;
import com.ticket.system.service.IYanchuMoviegoerService;
import com.ticket.common.utils.poi.ExcelUtil;
import com.ticket.common.core.page.TableDataInfo;

/**
 * 常用观演人信息关联关系Controller
 *
 * @author ruoyi
 * @date 2023-10-22
 */
@RestController
@RequestMapping("/system/moviegoer")
public class YanchuMoviegoerController extends BaseController {
    @Resource
    private IYanchuMoviegoerService yanchuMoviegoerService;
    @Resource
    private TokenService tokenService;

    /**
     * 查询常用观演人信息关联关系列表
     */
    @GetMapping("/list")
    public TableDataInfo list(YanchuMoviegoer yanchuMoviegoer) {
        startPage();
        List<YanchuMoviegoer> list = yanchuMoviegoerService.selectYanchuMoviegoerList(yanchuMoviegoer);
        return getDataTable(list);
    }

    @ApiOperation("小程序端——查询常用观演人信息")
    @GetMapping("/listMoviegoer")
    public TableDataInfo<UserInfoVo> listMoviegoer(HttpServletRequest request) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        startPage();
        List<UserInfoVo> list = yanchuMoviegoerService.selectMoviegoerByUserinfoId(loginUser.getUser().getUserId());
        return getDataTable(list);
    }

    /**
     * 导出常用观演人信息关联关系列表
     */
    @Log(title = "常用观演人信息关联关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YanchuMoviegoer yanchuMoviegoer) {
        List<YanchuMoviegoer> list = yanchuMoviegoerService.selectYanchuMoviegoerList(yanchuMoviegoer);
        ExcelUtil<YanchuMoviegoer> util = new ExcelUtil<YanchuMoviegoer>(YanchuMoviegoer.class);
        util.exportExcel(response, list, "常用观演人信息关联关系数据");
    }

    /**
     * 获取常用观演人信息关联关系详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(yanchuMoviegoerService.selectYanchuMoviegoerById(id));
    }

    /**
     * 新增常用观演人信息关联关系
     */
    @ApiOperation("小程序端——查询常用观演人信息")
    @ApiImplicitParam(name = "yanchuUserInfo", value = "观影人信息", dataType = "YanchuUserInfo", dataTypeClass = YanchuUserInfo.class)
    @Log(title = "常用观演人信息关联关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YanchuUserInfo yanchuUserInfo, HttpServletRequest request) {
        LoginUser loginUser = tokenService.getLoginUser(request);
        return yanchuMoviegoerService.addMoviegoer(yanchuUserInfo, loginUser.getUser().getUserId());
    }

    /**
     * 修改常用观演人信息关联关系
     */
    @Log(title = "常用观演人信息关联关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YanchuMoviegoer yanchuMoviegoer) {
        return toAjax(yanchuMoviegoerService.updateYanchuMoviegoer(yanchuMoviegoer));
    }

    /**
     * 删除常用观演人信息关联关系
     */
    @ApiOperation("常用观影人删除")
    @Log(title = "常用观演人信息关联关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(yanchuMoviegoerService.deleteYanchuMoviegoerByIds(ids));
    }
}
